﻿using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

///
///https://docs.microsoft.com/zh-cn/dotnet/framework/wpf/graphics-multimedia/easing-functions
///https://easings.net/zh-cn

[RequireComponent(typeof(Image))]
public class FadeOutEffect : MonoBehaviour {

    Tweener tweener;

    public bool autoStart = true;
    public float duration = 0.5f;
    public float alpha = 0f;
    public LoopType loop = LoopType.Restart;


    public void Play()
    {
        tweener.Play();
    }

    public void Pause()
    {
        tweener.Pause();
    }

    // Use this for initialization
    void Start () {
        Image img = GetComponent<Image>();

        tweener = img.DOFade(alpha, duration).SetLoops(-1, loop).SetAutoKill(false).Pause();

        if (autoStart)
        {
            tweener.Play();
        }
    }
	
	// Update is called once per frame
	void Update () {
		
	}
}
